from typing import Self
import pygame

class Pygame_Single:
    screen:pygame.Surface
    size=(1600,900)#窗口大小
    winName="window"#窗口名
    background_color=(255,255,240)#背景颜色
    instance = None
    font:pygame.font.Font
    def __new__(cls) -> Self:
        if(cls.instance is None):
            cls.instance = object.__new__(cls)
        return cls.instance

    def __init__(self) -> None:
        pygame.init()# 初始化pygame
        #size = (1600, 900)
        self.screen = pygame.display.set_mode(self.size)# 设置窗口大小
        pygame.display.set_caption(self.winName)# 设置窗口名
        self.screen.fill(self.background_color)# 设置背景颜色
        self.font = pygame.font.Font("font/DENGB.TTF",20)
        # text = self.font.render('hello pygame', True, (0, 255, 0))
        # self.screen.blit(text, (100, 100))
        self.Refresh()
    def Refresh(self):
        pygame.display.flip()#刷新窗口
    update=None
    
    def Wait(self):
        running = True
        while running:
            if(self.update!=None):
                self.update()
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    running = False
    def Clear(self):
        self.screen.fill(self.background_color)
        self.Refresh()

# Pygame_Single()
# Pygame_Single.instance.Refresh()
# Pygame_Single.instance.Wait()
